package com.liyunc.demo.comp.captcha;


import lombok.Data;
import lombok.NoArgsConstructor;

import java.awt.image.BufferedImage;
import java.time.LocalDateTime;

/**
 * @author liyuncong
 * @version 1.0
 * @file CaptchaPayload
 * @brief CaptchaPayload
 * @details CaptchaPayload
 * @date 2022-06-08
 *
 * Edit History
 * ----------------------------------------------------------------------------
 * DATE                        NAME               DESCRIPTION
 * 2022-06-08                      liyuncong          Created
 */
@Data
@NoArgsConstructor
public class CaptchaPayload {
    private BufferedImage image;
    private String code;
    private LocalDateTime expireTime;

    public CaptchaPayload(BufferedImage image, String code, long expireIn) {
        this.image = image;
        this.code = code;
        this.expireTime = LocalDateTime.now().plusSeconds(expireIn);
    }

    /**
     * 验证是否过期.
     */
    public boolean isExpire(CaptchaConfig config) {
        return LocalDateTime.now().isAfter(expireTime);
    }
}
